﻿<cfsilent>
	<cfscript>
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		chooseProp = getProperty("serviceFactory").getBean("choosePropertyAdvice");
		taskProp = getProperty("serviceFactory").getBean("taskPropertyAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");

		termId = event.getArg("TermID");

		/* 学籍相关信息 */
		studentId = sessionAdvice.getAutherUserID();
		
		/* 读取学生的已选课程 */
		sql = "SELECT 
				t_course.cid, t_course.course_name, t_course.course_credit, 
				t_choose_turn.turn, 
				task_type, scc_id, st, retaking, 
				choose_time, choose_prop, task_id, 
				t_course_prop.prop_name
				FROM t_student_course 
				INNER JOIN t_course ON t_course.cid = t_student_course.cid
				INNER JOIN t_choose_turn ON t_choose_turn.ct = t_student_course.ct 
				INNER JOIN t_course_prop ON t_course_prop.prop_id = t_student_course.prop_id 
				WHERE 
					stu_id = :studentId 
					AND 
					term_id = :termId 
				ORDER BY 
					st, t_course_prop.prop_name, t_course.course_name";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );

		rs_choosen = queryObj.execute( sql=sql ).getResult();

	</cfscript>
</cfsilent>

<cfif rs_choosen.recordCount>
	<table class="UIEditable">
		<thead>
			<tr>
				<td width="18"></td>
				<td>教学班</td>
				<td>任课教师</td>
				<td>学分</td>
				<!---<td>开课类别</td>--->
				<td>修读方式</td>
				<td>课程性质</td>
				<td>重修</td>
				<td>选课轮次</td>
				<td>选课时间</td>
			</tr>
		</thead>
		<tbody>
			<cfset row = 0 />
			<cfloop query="rs_choosen">
				<cfset row++ />
			
				<!--- 读取教学任务教师和任务性质 --->
				<cfscript>
					switch ( rs_choosen.task_type ) { 
						
						case "P":
							sql = "SELECT 
									t_teacher.tch_name, 
									task_prop, cidx
									FROM t_task t 
									INNER JOIN t_teacher ON t_teacher.tch_id = t.tch_id 
									INNER JOIN t_campus ON t_campus.campus_id = t.campus_id
									WHERE tsk_id = :taskId ";
							break;
						
						case "C":
							sql = "SELECT 
									t_teacher.tch_name, 
									task_prop, cidx
									FROM t_common_task t 
									INNER JOIN t_teacher ON t_teacher.tch_id = t.tch_id 
									INNER JOIN t_campus ON t_campus.campus_id = t.campus_id
									WHERE tsk_id = :taskId ";
							break;
						
						case "T":
							sql = "SELECT 
									t_teacher.tch_name, 
									task_prop, cidx
									FROM t_sport_task t 
									INNER JOIN t_teacher ON t_teacher.tch_id = t.tch_id 
									INNER JOIN t_campus ON t_campus.campus_id = t.campus_id
									WHERE tsk_id = :taskId ";
							break;
						
						case "R":
							sql = "SELECT 
									t_teacher.tch_name, 
									task_prop, cidx
									FROM t_reopen_task t 
									INNER JOIN t_teacher ON t_teacher.tch_id = t.tch_id 
									INNER JOIN t_campus ON t_campus.campus_id = t.campus_id
									WHERE tsk_id = :taskId ";
							break;
						
					}
					
					queryObj = new Query( datasource=application.dnsSlave );
					queryObj.addParam( name="taskId", value=rs_choosen.task_id, cfsqltype="cf_sql_varchar" );

					rs_task = queryObj.execute( sql=sql ).getResult();
					
				</cfscript>

				<cfif rs_task.recordCount>
					<!--- 如果教学任务有效 --->
					<cfset taskProp.parseProperty( rs_task.task_prop ) />
					<cfset chooseProp.parseProperty( rs_choosen.choose_prop ) />
					<tr class="editRows <cfif rs_choosen.st eq "R">noticeRow1</cfif> <cfif rs_choosen.st eq "F">noticeRow2</cfif>">
						<td><span class="index"><cfoutput>#row#</cfoutput></span></td>
						<td><cfoutput>#rs_choosen.course_name#</cfoutput>.-.<cfoutput>#rs_task.cidx#</cfoutput></td>
						<td><cfoutput>#rs_task.tch_name#</cfoutput></td>
						<td><span class="numeric"><cfoutput>#numberFormat(rs_choosen.course_credit, '_.__')#</cfoutput></span></td>
						<!---<td><cfoutput>#dictAdvice.getTaskType( rs_choosen.task_type )#</cfoutput></td>--->
						<td><cfoutput>#dictAdvice.getStudyType( rs_choosen.st )#</cfoutput></td>
						<td><cfoutput>#rs_choosen.prop_name#</cfoutput></td>
						<td><cfif rs_choosen.retaking eq "1">是</cfif></td>
						<td><cfoutput>#rs_choosen.turn#</cfoutput></td>
						<td><span class="numeric"><cfoutput>#datetimeAdvice.formatDatetimeString(rs_choosen.choose_time, 'YYYY-MM-DD HH:MI')#</cfoutput></span></td>
					</tr>
					<cfelse>
					<!--- 如果教学任务无效 则直接删除错误的选课记录 --->
				</cfif>
			</cfloop>
		</tbody>
	</table>
</cfif>
